<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                       version="1.0"
                       xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 
                       xmlns:xf="http://www.w3.org/2002/xforms" 
                       xmlns:ev="http://www.w3.org/2001/xml-events" 
                       xmlns:xhtml="http://www.w3.org/1999/xhtml"
                       xmlns="http://www.w3.org/1999/xhtml" 
                       xmlns:atom="http://www.w3.org/2005/Atom" 
                       xmlns:ui="urn:uuid:user-interface-patterns#">
    <xsl:template match="ui:existential-block">
        <!-- commented out for 1.0 XForms implementations -->        
        <!--xf:group ref="current()[not({@node})]">
            <img src="add.gif" alt="Add {@node}"/>
        </xf:group-->
        <xsl:apply-templates select="*"/>
    </xsl:template>
    <xsl:template match="ui:homogeneous-bucket">
      <xf:repeat nodeset="{@nodeset}">
        <xsl:apply-templates select="*"/>
      </xf:repeat>
      <xf:trigger>
        <xf:label>
          <xsl:value-of select="@addButton"/>
        </xf:label>
        <xf:action ev:event="DOMActivate">
          <xf:insert nodeset="{@nodeset}" at="1" position="after"/>
        </xf:action>
      </xf:trigger>      
    </xsl:template>
    <xsl:template match="xul:grid">   
        <table>
            <tbody>
                <xsl:for-each select="xul:rows/xul:row">
                    <tr>
                        <xsl:for-each select="*">
                            <xsl:variable name="curr-pos" select="position()"/>
                            <xsl:element name="xhtml:td" namespace="http://www.w3.org/1999/xhtml">
                                <xsl:for-each select="../../../xul:columns/xul:column[position() = $curr-pos]/@*">
                                    <xsl:copy-of select="."/>
                                </xsl:for-each>
                                <xsl:apply-templates select="."/>
                            </xsl:element>
                        </xsl:for-each>                        
                    </tr>                    
                </xsl:for-each>
            </tbody>            
        </table>    
    </xsl:template>
    <xsl:template match="xul:label">
        <span style="font-weight:bold;"><xsl:value-of select="text()"/></span>
    </xsl:template>
    <xsl:template match="xul:groupbox">        
        <fieldset>
            <xsl:apply-templates select="*"/>
        </fieldset>
    </xsl:template>
    <xsl:template match="xul:caption">
        <legend>
            <xsl:apply-templates select="* | @*"/>
        </legend>
    </xsl:template>    
    <xsl:template match="xul:caption/@label">
        <xsl:value-of select="text()"/>
     </xsl:template>
    <xsl:template match="ui:attribute-anchor">
        <xf:group ref="{@node}">
            <xsl:for-each select="ui:attribute">
              <xsl:element name="xf:input" namespace="http://www.w3.org/2002/xforms">
                <xsl:attribute name="ref"><xsl:value-of select="@attrName"/></xsl:attribute>
                <xsl:if test="@class">
                  <xsl:attribute name="class"><xsl:value-of select="@class"/></xsl:attribute>
                </xsl:if>
                <xf:label><xsl:value-of select="@label"/></xf:label>
              </xsl:element>
            </xsl:for-each>
        </xf:group>
    </xsl:template>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>